﻿#ifndef WEBUI_USER_H__
#define WEBUI_USER_H__

#include <string>
#include <streambuf>

#include <boost/asio.hpp>

#include "webui/CallbackTypes.h"

namespace webui {
	
class User
{
	typedef User this_t;
public:
	User(boost::asio::io_service& io, const callback_map_t& cb_map);
	~User();

	boost::asio::ip::tcp::socket& Socket() { return sock_; }
	
	void RunRecv();
private:

	void OnRecv_(const boost::system::error_code& err, std::size_t cb);

	template<typename Content>
	void Reply_( Content& text, size_t size, const std::string type, int code=200 );

	void Reply_Error_( int code );

	void OnSent_(const boost::system::error_code& err, std::size_t cb)
	{
		delete this;
	}	

private:
	boost::asio::ip::tcp::socket sock_;
	boost::asio::streambuf buf_in_;
	boost::asio::streambuf buf_out_;

	bool head_;

	const callback_map_t& cb_map_;
};

} // namespace webui

#endif // WEBUI_USER_H__